package com.farmer.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.farmer.pojo.Poorapply;
import com.farmer.service.PoorapplyService;
import com.farmer.utils.Result;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@CrossOrigin
@RestController
@RequestMapping("poorapply")
public class PoorApplyController {
    @Autowired
    private PoorapplyService poorapplyService;
/*
    @PostMapping("add")
    public Result add( @RequestHeader String token,@RequestBody Poorapply poorapply,@RequestBody MultipartFile file) {
        Result result =poorapplyService.add(token,poorapply,file);
        return result;
    }
    */

    @PostMapping("add")
    public Result add( @RequestHeader String token,@RequestBody Poorapply poorapply) {
    Result result =poorapplyService.add(token,poorapply);
    return result;
  }

    @DeleteMapping("delete")
    public Result delete(@RequestParam("id") Integer id) {
        Result result = poorapplyService.delete(id);
        return result;
    }

    @PutMapping("update")
    public Result update(@RequestBody Poorapply poorapply) {
        Result result = poorapplyService.update(poorapply);
        return result;
    }

    @GetMapping("getById")
    public Result getById(@RequestParam Integer id) {
        Result result = poorapplyService.getById(id);
        return result;
    }

    @GetMapping("getAll")
    public Result getAll() {
        Result result = poorapplyService.getAll();
        return result;
    }

    /*
     * 根据标题模糊查询*/
    @GetMapping("getByTitleLike")
    public Result getByTitleLike(@RequestParam String status){
        Result result = poorapplyService.getByTitleLike(status);
        return result;
    }

    /*
    * 前台用户上传资料*/
    @PostMapping("uploadFile")
    public  Result uploadFile(@RequestParam Integer id, @RequestBody MultipartFile file){
        Result result = poorapplyService.uploadFile(id,file);
        return result;
    }


    @GetMapping("page")
    public Result page(@RequestParam(defaultValue = "1") Integer pageNum,
                       @RequestParam(defaultValue = "10") Integer pageSize) {
        Result result = poorapplyService.page(pageNum,pageSize);
        return result;
    }
    /*
    * 根据用户token获取个人申请*/
    @GetMapping("getPoorapplyListByToken")
    public Result getPoorapplyListByToken(@RequestHeader String token){
        Result result = poorapplyService.getPoorapplyListByToken(token);
        return result;
    }
}
